package com.aya.project;

import com.aya.project.UserContext;
import com.aya.tb.context.ArgumentSupportHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.Attribute;
import io.netty.util.AttributeKey;
import org.springframework.stereotype.Service;

import java.lang.reflect.Parameter;
@Service
public class UserContextArgumentSupportHandler implements ArgumentSupportHandler {
    @Override
    public boolean support(Parameter parameter, byte[] body, ChannelHandlerContext ctx) {
        return UserContext.class.isAssignableFrom(parameter.getType());
    }

    @Override
    public Object handler(Parameter parameter, byte[] body, ChannelHandlerContext ctx) {
        Attribute<Object> attr = ctx.channel().attr(AttributeKey.valueOf("USER_CONTEXT"));
        return attr.get();
    }
}
